package resource 
{
	import com.adobe.serialization.json.JSON;
	import flash.events.Event;
	import flash.events.IOErrorEvent;
	import flash.events.SecurityErrorEvent;
	import flash.net.URLLoader;
	import flash.net.URLRequest;
	import flash.utils.ByteArray;
	/**
	 * ...
	 * @author carlor
	 */
	public class JsonResource extends Resource
	{
		private var _loader: URLLoader;
		private var _data  : Object;
		
		public function JsonResource() 
		{
			super();
		}
		
		override public function load(fileName: String): void
		{
			super.load(fileName);
			_loader = new URLLoader();
			_loader.addEventListener(Event.COMPLETE, onLoadComplete);
			_loader.addEventListener(IOErrorEvent.IO_ERROR, onLoadError);
			_loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onLoadSecurityError);
			_loader.load(new URLRequest(fileName));
		}
		
		override public function unLoad(): void
		{
			_loader = null;
		}	
		
		override protected function onLoadComplete(e: Event): void
		{
			_data = JSON.decode(e.currentTarget.data);
			super.onLoadComplete(e);
		}
		
		public function get data(): Object
		{
			return _data;
		}		
	}

}